/* 
 * File:   FiltreCompute.cpp
 * Author: amouro-m
 * 
 * Created on 15 mai 2010, 11:26
 */

#include "tbb/parallel_for.h"

#include "FiltreCompute.hpp"
#include "FractalPrinter.h"

FiltreCompute::FiltreCompute(Filtre& filtre, FractalPrinter* fp):
_filtre(filtre),
_fp(fp)
{}

FiltreCompute::~FiltreCompute() {}

void
FiltreCompute::operator() (const tbb::blocked_range2d<unsigned int, unsigned int> & r) const
{
    tbb::blocked_range2d<unsigned int>::row_range_type rows = r.rows();
    tbb::blocked_range2d<unsigned int>::col_range_type cols = r.cols();
    for (unsigned int i = rows.begin(); i < rows.end(); ++i)
        for (unsigned int j = cols.begin(); j < cols.end(); ++j)
            _filtre.compute(_fp->get_area(), i, j);
    _fp->repaint();
}

void
FiltreCompute::ParallelCompute(Filtre& filtre, FractalPrinter* fp)
{
    tbb::parallel_for(tbb::blocked_range2d<unsigned int, unsigned int>(0, fp->get_width(), 0, fp->get_height()), FiltreCompute(filtre, fp));
}